package com.orphan.supplier.controller;


import com.orphan.supplier.po.Back;
import com.orphan.supplier.service.IBackService;
import com.orphan.supplier.vo.BackVo;
import com.orphan.util.mqConfig.MQUtil;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zjm
 * @since 2021-07-14
 */
@RestController
@RequestMapping("/back")
@Api(value = "供应商退货入口")
public class BackController {

    @Autowired
    IBackService backService;

    @Resource
    private MQUtil mqUtil;
    @GetMapping("/findAll")
    @ResponseBody
    public List<BackVo>findAll(){
        return backService.findAll();
    }

    @RequestMapping("findById")
    @ResponseBody
    public Back findById(String OrderId){
        return backService.findById(OrderId);
    }

    @GetMapping("/findByItem")
    public Object findAll(int pageNO,String state){
        return backService.findByItem(pageNO, state);
    }

    @DeleteMapping("/delBackOrder")
    public Object delBackOrder(String OrderId){
        backService.delBackOrder(OrderId);
        return "success";
    }
    @PostMapping("/addBackOrder")//发送消息队列
    public Object addReturnOrder(Back back){
        mqUtil.send("directExchangeaudit","audit",back);
        return null;
    }
    @GetMapping("/updateStats")
    public Object updateStats(String OrderId, Integer goodsNum, String goodsName){
        backService.updateBackOrderState(OrderId, goodsNum, goodsName);
//        调用审核系统的接口，修改审核系统的供应商退货状态
        mqUtil.send("directExchangeaudit", "audit",OrderId);
        return "ok";
    }
}
